Hey there.
I have one last practice problem for you to solve before we move on to making games on roadblocks.
Your task is this.
I'd like you to create a function that takes a number argument using that number.
I want you to check if it's divisible by three.
If so, you'll print physx.
If the number is divisible by five, then you'll print buzz.
Otherwise, if the number is divisible by both three and five, you'll print physx Buzz.
Please take a minute or two to solve this problem and I'll show you my solution next.
Okay to solve this problem, I'll first create my function.
Call it fizz buzz.
And have a parameter named num.
Next I'll create an if statement and first check if the num is divisible by both three and five using
the modulus operator.
I check if the return from this operation is zero, meaning that no remainder was left over and this
number is divisible by three and five.
I check this one first because the most complex conditions should be at the top of your if statements
with conditions that reducing complexity to go further and further down your if statements.
This is because if I had this complex condition at the end and pass a number like 15, it would never
print fiz buzz because condition like num modulus three would evaluate to true and ignore all the rest.
15 can also be divided by five.
So if that was the first condition to be checked, it would evaluate the true and ignore the other conditions.
So if I have my complex condition at the bottom, I'll never be able to reach it due to the less complex
conditions above it.
Next, I'll do live and check to see if the num is divisible by three.
If so, I'll print fiz.
And lastly, I'll check for the number is divisible by five.
And if so, I'll print buzz.
Now I can call this function and pass the number like 15 and it should print fizz buzz.
Let's run the script.
And perfect.
We get fizz buzz.
Now in the test.
Pass five instead of my function and then run my game again.
And it should print buzz.
Okay.
The last number I'll pass is three.
And it should print fiz.
Excellent.